package com.aegean.CommercialHotelBookSystem.user.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aegean.CommercialHotelBookSystem.model.Book;
import com.aegean.CommercialHotelBookSystem.model.Hotel;

/**
 * Servlet implementation class BookServiceAction
 */
public class BookServiceAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public BookServiceAction() {
		super();
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int page;
		if (request.getParameter("page") == null) {
			page = 0;
		} else {
			page = Integer.parseInt(request.getParameter("page")) - 1;
		}
		HttpSession session = request.getSession();
		List<Book> books = (List<Book>) session.getAttribute("User_Books");
		List<Book> books2 = new ArrayList<Book>();
		int size = 15;
		if (books == null || books.isEmpty()) {
		} else {
			for (int i = page * size; i < page * size + size; i++) {
				Book one = books.get(i);
				books2.add(one);
				if (i == books.size() - 1) {
					break;
				}
			}
		}
		request.setAttribute("User_Books", books2);
		request.getRequestDispatcher("User_book.jsp")
				.forward(request, response);
	}

}
